package com.educate.service.impl;

import com.educate.common.dto.EditCourseDto;
import com.educate.dao.EditCourseDao;
import com.educate.pojo.Video;
import com.educate.service.EditCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author yjj
 * @date 2021/12/20
 * @Description  编辑课程实现
 */
@Service
public class EditCourseServiceImpl implements EditCourseService {

    @Autowired
    private EditCourseDao editCourseDao;

    /**
     * 修改课程基本信息
     * @param editCourseDto
     */
    @Override
    public void updateCourse(EditCourseDto editCourseDto) {
        editCourseDao.updateCourse(editCourseDto);
    }

    /**
     * 增加课程视频
     * @param fileName
     */
    @Override
    @Transactional
    public void addCourseVideo(String courseId, int playTime, String fileName) {
        //视频实体
        Video video = new Video();
        video.setFileName(fileName);
        video.setPlayTime(playTime);
        //在视频表中增加记录
        int flag = editCourseDao.addCourseVideo(video);
        if(flag == 1){
            Long id = Long.valueOf(courseId);
            //将此视频实体与对应课程实体相绑定
            editCourseDao.addCourseLinkVideo(id,video.getId());
        }
    }
}
